package com.example.cd5160866.tabs;

import java.util.Random;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class Test {

    private static ExecutorService service = Executors.newFixedThreadPool(20);

    public static void main(String[] args) {
        testTask();
//        testTask(2);
    }

    private static void testTask() {
        for (int i = 0; i < 50; i++) {
            testTask(i);
        }
    }

    private static void testTask(final int taskName) {
        Runnable runnable = new Runnable() {
            @Override
            public void run() {
                try {
                    int randomTime = new Random().nextInt(1000);
                    Thread.sleep(randomTime);
                    System.out.print("线程 " + taskName + "耗时" + randomTime + "执行完成 \n");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        };
        service.submit(runnable);
    }


}
